<?php
class TeacherAction extends AppAction
{
	function __construct()
	{
		parent::__construct ();
		require_once APP_LIB_PATH . 'teacherLib.php';
		$this->lib = new TeacherLib ();
		AdminVisitor::checkGrant ( 'teacher' );
	}
	
	public function teacherlist()
	{
		ViewData::$form_data->list = $this->lib->getTeacherList ();
		BaseAction::loadView ( 'admin/teacherList' );
	}
	public function exportexcel()
	{
		if (isset ( $_POST ['Id'] ) && isset ( $_GET ['menu'] ))
		{
			if ($_GET ['menu'] == 'exportExcel')
			{
				$this->lib->exportExcel ( $_POST ['Id'] );
			}
		}
		BaseAction::adminError ( "请不要非法操作" );
	}
	
	public function teacherEdit()
	{
		if (! isset ( $_GET ['teacherId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		ViewData::$form_data = $this->lib->getById ( $_GET ['teacherId'] );
		ViewData::$form_hint = new RegisteTeacherClass ();
		if ($_POST)
		{
			$this->lib->checkEditForm ();
			if (! BaseAction::isObjectEmpty ( ViewData::$form_hint ))
			{
				BaseAction::loadView ( "admin/teacherEdit" );
			}
			try
			{
				$this->lib->editLogic ( $_GET ['teacherId'] );
				BaseAction::adminSuccess ( "修改成功", siteUrl ( 'teacher/teacherlist' ) );
			} catch ( Exception $e )
			{
				ViewData::$form_hint->Message = $e->getMessage ();
			}
		}
		BaseAction::loadView ( "admin/teacherEdit" );
	}
	
	public function teacherView()
	{
		if (! isset ( $_GET ['teacherId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		$this->lib->editTeacherStatusLogic( $_GET ['teacherId'], 1) ;
		ViewData::$form_data = $this->lib->getById ( $_GET ['teacherId'] );
		BaseAction::loadView ( "admin/teacherView" );
	}
	
	public function teacherdel()
	{
		if (! isset ( $_GET ['teacherId'] ))
		{
			BaseAction::adminError ( "请不要非法访问" );
		}
		$this->lib->delByTeacherId ( $_GET ['teacherId'] );
		BaseAction::adminSuccess ( "删除成功", siteUrl ( 'teacher/teacherlist' ) );
	}
}